package com.jichangxiu.dynamic.test.service.impl;

import com.jichangxiu.dynamic.test.config.SelectDB;
import com.jichangxiu.dynamic.test.entity.Monster;
import com.jichangxiu.dynamic.test.mapper.MonsterMapper;
import com.jichangxiu.dynamic.test.service.MonsterService;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * @author Jcx
 * @date 2022/11/26 21:33
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MonsterServiceImpl extends BaseServiceImpl<MonsterMapper, Monster> implements MonsterService {

    @SelectDB(dbName = "t2")
    @Override
    public Future<Boolean> saveMonster(Monster monster) {
        return new AsyncResult<>(save(monster));
    }

    @SelectDB(dbName = "t2")
    @Override
    public CompletableFuture<List<Monster>> myList() {
        List<Monster> monsters = list();
        monsters.forEach(System.out::println);
        return CompletableFuture.completedFuture(monsters);
    }

}
